package main.java.indi.zyj.hot100;

import main.java.indi.zyj.hot100.base.TreeNode;

public class _01_sortedArrayToBST {

    public TreeNode sortedArrayToBST(int[] nums) {

        int left = 0, right = nums.length - 1;

        return sort(nums, left, right);

    }

    private TreeNode sort(int[] nums, int left, int right) {

        TreeNode node;
        if (left <= right) {
            int mid = (right - left)/2 + left;
            node = new TreeNode(nums[mid]);
            node.left = sort(nums, left, mid - 1);
            node.right = sort(nums, mid + 1, right);
        } else {
            return null;
        }

        return node;

    }


}
